package oss

import (
	"admin.supervise.limaochuxing.top/admin/schemas/req"
	"admin.supervise.limaochuxing.top/admin/service/oss"
	"admin.supervise.limaochuxing.top/core"
	"admin.supervise.limaochuxing.top/core/response"
	"admin.supervise.limaochuxing.top/middleware"

	"admin.supervise.limaochuxing.top/util"

	"github.com/gin-gonic/gin"
)

var OssGroup = core.Group("/oss", newOssHandler, regOss, middleware.TokenAuth())

func newOssHandler(srv oss.IOssService) *ossHandler {
	return &ossHandler{srv: srv}
}

func regOss(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *ossHandler) {
		rg.POST("/upload-file", handle.uploadFile)
	})
}
type ossHandler struct {
	srv oss.IOssService
}
func (s ossHandler) uploadFile(c *gin.Context) {
	var req req.OssUploadFileReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &req)) {
		return
	}
	data,err := s.srv.UploadFile(req.File)
	response.CheckAndRespWithData( c,data,err)
}